<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <link rel="shortcut icon" href="#"/>
    <link rel="stylesheet" href="../element-ui/element.css">
    <style>
        .login {
            background: url("${pageContext.request.contextPath}/cln/images/bg.jpg") no-repeat center center;
            width: 100%;
            height: 100%;
            background-size: 100% 100%;
            position: fixed;
        }
        .bg{
            background-color: white;
            width: 450px;
            height: 370px;
            position: absolute;
            top: 45%;
            left: 75%;
            transform:translate(-50%,-50%);
        }
        .tabs{
            width: 400px;
            height: 300px;
            margin: 0 auto;
            /*为了垂直居中*/
            position: absolute;
            top: 45%;
            left: 50%;
            transform:translate(-50%,-50%);
        }
    </style>
</head>
<body>
<script src="../../vue/vue.js"></script>
<script src="../element-ui/element.js"></script>
<script src="../../jquery/jquery-3.4.1.js"></script>
<div id="login">
    <template>
        <!--element的Tabs组件 选项卡功能-->
        <div class="login">
            <div class="bg">
            <el-tabs v-model="activeName" @tab-click="handleClick" class="tabs">
                <el-tab-pane label="登录" name="first">
                    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                        <el-form-item label="用户名" prop="username">
                            <el-input v-model="ruleForm.username"></el-input>
                        </el-form-item>
                        <el-form-item label="密码" prop="password">
                            <el-input type="password" v-model="ruleForm.password" auto-complete="off"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="success" @click="login">登录</el-button>
                            <el-button @click="resetForm('ruleForm')">重置</el-button>
                        </el-form-item>
                    </el-form>
                </el-tab-pane>
                <el-tab-pane label="注册" name="second">
                    <div id="register">
                        <iframe src="./register.jsp" align="center" width="100%" height="400" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
                    </div>
                </el-tab-pane>
            </el-tabs>
            </div>
        </div>
    </template>
</div>
</body>
<script>
    var Main = {
        name: 'Login',
        data() {
            var validatePass = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请输入密码'))
                } else {
                    if (this.ruleForm.checkPass !== '') {
                        this.$refs.ruleForm.validateField('checkPass')
                    }
                    callback()
                }
            };
            return {
                activeName: 'first',
                ruleForm: {
                    username: '',
                    password: '',
                    checkPass: '',
                    code: ''
                },
                rules: {
                    password: [{required: true, validator: validatePass, trigger: 'blur'}]
                },
                responseResult: []
            }
        },
        methods: {
            // 选项卡切换
            handleClick(tab, event) {
            },
            // 重置表单
            resetForm(formName) {
                this.$refs[formName].resetFields()
            },
            login(){
                $.ajax({
                    type: 'post',
                    url: '/forum/user/login',
                    dataType: 'json',
                    data:{
                        userName:this.ruleForm.username,
                        userPassword:this.ruleForm.password
                    },
                    success: function (data) {
                        console.log(data)
                        if (data.state === '200') {
                            window.location.href = "../../3_main/3_main.html";
                        }
                    }
                })
            }
        }
    };
    var Ctor = Vue.extend(Main);
    new Ctor().$mount('#login');
</script>
</html>
